﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     GBAD业务接口的实现
    /// 作者：     Wilson
    /// 日期：     2011/10/23
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class GBADSqlMapDao : BaseSqlMapDao, AUV5.DAL.Interface.IGBADDao
    {
        private static GBADSqlMapDao instance = new GBADSqlMapDao();

        private GBADSqlMapDao()
        {
            //
            // TODO: 此处添加GBADSqlMapDao的构造函数
            //
        }

        public static IGBADDao GetInstance()
        {
            return instance;
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectGBADByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<GBAD> GetList()
        {
            try
            {
                return ExecuteQueryForList<GBAD>("SelectGBAD", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<GBAD> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<GBAD>("SelectGBADByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="ADID"></param>
        /// <returns></returns>
        public GBAD GetDetail(System.String adid)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("ADID", adid);
                return ExecuteQueryForObject<GBAD>("SelectGBAD", ht) as GBAD;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public object Add(GBAD gbad)
        {
            //int id = GetId("GBAD");
            //gbad.ADID = id;

            try
            {
                return ExecuteInsert("InsertGBAD", gbad);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public int Update(GBAD gbad)
        {
            try
            {
                return ExecuteUpdate("UpdateGBAD", gbad);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ADID"></param>
        /// <returns></returns>
        public int Delete(System.String adid)
        {
            try
            {
                return ExecuteDelete("DeleteGBAD", adid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="gbad"></param>
        /// <returns></returns>
        public int Delete(GBAD gbad)
        {
            try
            {
                return ExecuteDelete("DeleteGBAD", gbad.ADID);
            }
            catch
            {
                throw;
            }
        }

        #region IGBADDao 成员

        /// <summary>
        /// 通过父编码得到集合
        /// </summary>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        public IList<GBAD> GetListByADParentCode(string parentCode)
        {
            try
            {
                return ExecuteQueryForList<GBAD>("SelectGBADByADParentCode", parentCode);
            }
            catch 
            {
                
                throw;
            }
        }

        #endregion

        public GBAD GetDetailByCode(string code)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("code", code);
                return ExecuteQueryForObject("SelectGBAD", ht) as GBAD;
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
